//
//  KSActionSheet.m
//  XiangMu
//
//  Created by 康世标 on 15/8/14.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "KSActionSheet.h"
#import "Header.h"
@implementation KSActionSheet

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithActionSheet{
    
    if (self=[super init])
    {
        self.frame=[UIScreen mainScreen].bounds;
//        self.backgroundColor=[UIColor colorWithRed:248/255 green:248/255 blue:248/255 alpha:0.2];
        UIView * bjView=[[UIView alloc]init];
        
        bjView.backgroundColor=CL_f2f2f2;
        bjView.layer.masksToBounds=YES;
        [bjView.layer setCornerRadius:10];
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundImage:[UIImage imageNamed:@"weixin"] forState:UIControlStateNormal];
       [btn addTarget:self action:@selector(HaoYou:) forControlEvents:UIControlEventTouchUpInside];
        [bjView addSubview:btn];
        UILabel *lable=[[UILabel alloc]init];
        
        lable.text=@"微信好友";
        
        lable.font=[UIFont systemFontOfSize:12];
        
        [bjView addSubview:lable];
        
        UIButton *btn2 =[UIButton buttonWithType:UIButtonTypeCustom];

        [btn2 setBackgroundImage:[UIImage imageNamed:@"pengyoujuan"] forState:UIControlStateNormal];
        [btn2 addTarget:self action:@selector(PengYouQuan:) forControlEvents:UIControlEventTouchUpInside];
        [bjView addSubview:btn2];
        UILabel *lable1=[[UILabel alloc]init];
        
        lable1.text=@"朋友圈";
        
        lable1.font=[UIFont systemFontOfSize:12];
        
        [bjView addSubview:lable1];

        [self addSubview:bjView];
        
        [bjView mas_makeConstraints:^(MASConstraintMaker *make) {
//            白色view 高度 60  self 代表据那个试图
            make.height.mas_equalTo(@60);
//            据左边
            make.left.equalTo(self).with.offset(10);
//            据底部
            make.bottom.equalTo(self).with.offset(-50);
//            据右边
            make.right.equalTo(self).with.offset(-10);
            
        }];
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(bjView).with.offset(20);
            make.top.equalTo(bjView).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(36, 30));
            
        }];
        
        [lable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bjView).with.offset(16);
            make.top.equalTo(btn).with.offset(25);
            make.size.mas_equalTo(CGSizeMake(50, 30));
            
        }];
        [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(bjView).with.offset(-20);
            make.top.equalTo(bjView).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(29, 29));

        }];
        [lable1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(bjView).with.offset(-12);
            make.top.equalTo(btn).with.offset(25);
            make.size.mas_equalTo(CGSizeMake(40, 30));
            
        }];

        UIButton *quXiao=[UIButton buttonWithType:UIButtonTypeCustom];
        
        quXiao.backgroundColor=[UIColor whiteColor];
        quXiao.layer.masksToBounds=YES;
        [quXiao.layer setCornerRadius:5];
        [quXiao setBackgroundColor:CL_00cc85];
        [quXiao setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [quXiao setTitle:@"取       消" forState:UIControlStateNormal];
        [quXiao addTarget:self action:@selector(quxiao:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:quXiao];
        
        [quXiao mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(self).with.offset(-10);
            make.height.mas_equalTo(30);
            make.left.equalTo(self).offset(10);
            make.right.equalTo(self).offset(-10);
            
        }];
        
        UILabel * l1=nil ;
        
        [l1 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self).offset(50);
            make.right.equalTo(self).offset(0);
            make.top.equalTo(self).offset(200);
            make.height.mas_equalTo(@100);
            
        }];

    }
    return self;
    
}
- (void)show{
    AppDelegate *app =(AppDelegate *)[UIApplication sharedApplication].delegate;

    
   
    UIView * view1 = [[UIView alloc]initWithFrame:self.frame];
    
    view1.tag = 1001;
    view1.backgroundColor =[UIColor colorWithRed:248/255 green:248/255 blue:248/255 alpha:0.2];

   [app.window addSubview:view1];
    [app.window addSubview:self];
    
}
- (void)quxiao:(UIButton *)sender{
    

    [self removeSubView];
}
- (void)HaoYou:(UIButton *)sender{
    if ([_delegate respondsToSelector:@selector(alertView:clickedButtonAtIndexPantex:)] )
    {
        [_delegate alertView:self clickedButtonAtIndexPantex:1];
    }
    [self removeSubView];

}
- (void)PengYouQuan:(UIButton *)sender{
    if ([_delegate respondsToSelector:@selector(alertView:clickedButtonAtIndexPantex:)] )
    {
        [_delegate alertView:self clickedButtonAtIndexPantex:2];
    }
    [self removeSubView];
}


- (void)removeSubView{
    
    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    UIView * v = (UIView *)[app.window viewWithTag:1001];
    
    
    [v removeFromSuperview];
    
    [self removeFromSuperview];
}
@end
